package cn.com.w.dao.Service.Impl;


import cn.com.w.common.VO.BaseVO;
import cn.com.w.dao.Entity.SysUser;
import cn.com.w.dao.Service.ISysUserService;
import cn.com.w.dao.Service.RegisterJudgeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * @author w
 * @Description:
 * @DateTime: 2025 05 07 19:47
 **/
@Service
public class EmailJudgeServiceImpl implements RegisterJudgeService {

    private final ISysUserService userService;

    @Autowired
    public EmailJudgeServiceImpl(ISysUserService userService) {
        this.userService = userService;
    }

    @Override
    public void check(String other) throws Exception {
        if (!other.contains("@") && !other.contains(".")) {
            BaseVO.error("不符合邮件的格式！");
        }
        LambdaQueryWrapper<SysUser> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(SysUser::getEmail, other);
        if (userService.count(wrapper) > 0) {
            BaseVO.error("已存在相同邮件！");
        }
    }
}